const http = require('../../http.js')
Page({
  data: {},
  onLoad() {},
  onGetAuthorize() {//授权基本信息
    // my.getAuthCode({
    //   scopes: 'auth_user',
    //   success: ({ authCode }) => {
    //     this.data.userinfo=authCode
    //     //console.log(this.data.userinfo)
    //     // http.get('/api/alipay/aliLogin',{code:authCode}).then(res => {
    //     //     if (res.code == 200) {
    //     //       //my.setStorageSync("token", res.result.token);
    //     //     }
    //     // })
    //   },
    // });
    my.getOpenUserInfo({
      fail: (error) => {
        console.error('getAuthUserInfo', error);
      },
      success: (res) => {
        console.log(`userInfo:`, res);
        http.get('/api/alipay/aliLogin',{code:this.data.userinfo,encryptedData:encryptedData}).then(res => {
          if (res.code == 200) {
            console.log(res)
          }
        })
        let userInfo = JSON.parse(res.response).response // 以下方的报文格式解析两层 response
        this.setData({
          mockAvatar:'https://tfs.alipayobjects.com/images/partner/T1dH8EXcFeXXXXXXXX',
          userInfo,
        });
        console.log(userInfo)
        my.alert({
          content:JSON.stringify(userInfo)
        });
      }
    });
  },
  onGetAuthorize1(){//授权手机号
    console.log('asd')
    my.getPhoneNumber({
        success: (res) => {
            let encryptedData = res.response;
            console.log(encryptedData)
            http.get('/api/alipay/aliLogin',{code:this.data.userinfo,encryptedData:encryptedData}).then(res => {
                if (res.code == 200) {
                  console.log(res)
                }
            })
        },
        fail: (res) => {
            console.log(res);
            console.log('getPhoneNumber_fail');
        },
    });
  }
});
